package com.zking.myservlet.product;

import com.zking.dao.OrderDetailDao;
import com.zking.dao.ProductDao;
import com.zking.entity.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/manage/ProductDeleteById")
public class ProductDeleteById extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");
        int id = Integer.parseInt(req.getParameter("id"));
        boolean flag = ProductDao.deleteProduct(id);
        if(flag){
            resp.sendRedirect("ProductList");
        }
    }
}
